package com.nep.NEPM.controller;

import com.nep.NEPM.utils.ViewUtils;
import com.nep.entity.administrator.User;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;

import static com.nep.NEPM.utils.ViewUtils.loadView;

public class ProvinceGroViewController {
    @FXML
    private Button btn_OUT;
    @FXML
    private Button btn_SupervisorList;
    @FXML
    private Button btn_ConfirmAQIlist;
    @FXML
    private Button btn_ProvinceGro;
    @FXML
    private Button btn_AQIDistributeTotalStatis;
    @FXML
    private Button btn_AQITrend;
    @FXML
    private Button btn_Others;

    public void OUT(ActionEvent actionEvent) throws IOException {
        FXMLLoader fxmlLoader = new FXMLLoader();
        URL url = getClass().getResource("../view/IndexView.fxml");
        fxmlLoader.setLocation(url);
        Parent root = fxmlLoader.load();
        Scene scene = btn_OUT.getScene();
        scene.setRoot(root);
    }

    public void SupervisorList() throws IOException {
        Parent root = ViewUtils.loadView("../view/SupervisorListView.fxml");
        Stage stage = (Stage) btn_SupervisorList.getScene().getWindow();
        Scene scene = btn_SupervisorList.getScene();
        scene.setRoot(root);
        stage.setScene(scene);
        stage.show();
    }

    public void ConfirmAQIList() throws IOException {
        Parent root = ViewUtils.loadView("../view/ConfirmAQIListView.fxml");
        Stage stage = (Stage) btn_ConfirmAQIlist.getScene().getWindow();
        Scene scene = btn_ConfirmAQIlist.getScene();
        scene.setRoot(root);
        stage.setScene(scene);
        stage.show();
    }

    public void ProvinceGro() throws IOException {
        Parent root = ViewUtils.loadView("../view/ProvinceGroView.fxml");
        Stage stage = (Stage) btn_ProvinceGro.getScene().getWindow();
        Scene scene = btn_ProvinceGro.getScene();
        scene.setRoot(root);
        stage.setScene(scene);
        stage.show();
    }

    public void AQIDistributeTotalStatis() throws IOException {
        Parent root = ViewUtils.loadView("../view/AQIDistributeTotalStatis.fxml");
        Stage stage = (Stage) btn_AQIDistributeTotalStatis.getScene().getWindow();
        Scene scene = btn_AQIDistributeTotalStatis.getScene();
        scene.setRoot(root);
        stage.setScene(scene);
        stage.show();
    }

    public void AQITrend() throws IOException {
        Parent root = ViewUtils.loadView("../view/AQITrendView.fxml");
        Stage stage = (Stage) btn_AQITrend.getScene().getWindow();
        Scene scene = btn_AQITrend.getScene();
        scene.setRoot(root);
        stage.setScene(scene);
        stage.show();
    }

    public void Others() throws IOException {
        Parent root = ViewUtils.loadView("../view/OthersView.fxml");
        Stage stage = (Stage) btn_Others.getScene().getWindow();
        Scene scene = btn_Others.getScene();
        scene.setRoot(root);
        stage.setScene(scene);
        stage.show();
    }


    @FXML
    private TableColumn<User, String> colId,colProvinceAbe,colProvince,colSOExceed,colCOExceed,colPMExceed,colAQIExceed;
    @FXML
    private TableView<User> tableView;

    private ObservableList<User> userList = FXCollections.observableArrayList(
            new User("1", "京", "北京市", 1, 2, 1, 2),
            new User("2", "津", "天津市", 0, 1, 1, 1),
            new User("3", "冀", "河北省", 1, 0, 1, 1),
            new User("4", "晋", "山西省", 2, 4, 3, 4),
            new User("5", "蒙", "内蒙古自治区", 1, 1, 0, 1),
            new User("6", "辽", "辽宁省", 4, 3, 4, 4),
            new User("7", "吉", "吉林省", 0, 1, 1, 1),
            new User("8", "黑", "黑龙江省", 2, 2, 1, 3),
            new User("9", "沪", "上海市", 2, 1, 3, 3),
            new User("10", "苏", "江苏省", 3, 1, 3, 3),
            new User("11", "浙", "浙江省", 3, 2, 3, 3),
            new User("12", "皖", "安徽省", 2, 2, 2, 2),
            new User("13", "闽", "福建省", 2, 2, 2, 2)
    );

    public void initialize() {
        tableView.setItems(userList);
        colId.setCellValueFactory(new PropertyValueFactory<>("id"));
        colProvinceAbe.setCellValueFactory(new PropertyValueFactory<>("provinceAbe"));
        colProvince.setCellValueFactory(new PropertyValueFactory<>("province"));
        colSOExceed.setCellValueFactory(new PropertyValueFactory<>("SOExceed"));
        colCOExceed.setCellValueFactory(new PropertyValueFactory<>("COExceed"));
        colPMExceed.setCellValueFactory(new PropertyValueFactory<>("PMExceed"));
        colAQIExceed.setCellValueFactory(new PropertyValueFactory<>("AQIExceed"));
    }

}
